
<%@ page contentType="text/html; charset=utf-8" 
%><%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" 
%><%@ taglib uri="http://java.sun.com/jsp/jstl/functions" prefix="fn" 
%><%@ taglib uri="http://java.sun.com/jsp/jstl/fmt" prefix="fmt" 
%><!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<title>tree.jsp</title>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<%@ include file="/jsp/common/include.base.jsp" %>
<jsp:include page="/jsp/common/include.commoncode.jsp" flush="false"><jsp:param name="gp" value="1,2"/></jsp:include>
<%@ include file="/jsp/common/include.jqgrid.jsp" %>
<%@ include file="/jsp/common/include.form.jsp" %>
<script src="${pageContext.request.contextPath}/js/common/tree.js" type="text/javascript"></script>
<script type="text/javascript">

Array.prototype.peek = function() {
    if (this.length > 0) {
        return this[this.length - 1];   
    } else {
        return;
    }
}   

var MENU = 
{
PRNTS_ID: "", MENU_ID: "1", MENU_NM: "M-1", child: [
    {PRNTS_ID: "1", MENU_ID: "11", MENU_NM: "M-11", child: [
        {PRNTS_ID: "11", MENU_ID: "111", MENU_NM: "M-111", child: [
            {PRNTS_ID: "111", MENU_ID: "1111", MENU_NM: "M-1111", child: [
                {PRNTS_ID: "1111", MENU_ID: "11111", MENU_NM: "M-11111", child: []},                                                         
                {PRNTS_ID: "1111", MENU_ID: "11112", MENU_NM: "M-11112", child: []},                                                         
                {PRNTS_ID: "1111", MENU_ID: "11113", MENU_NM: "M-11113", child: []}                                                         
            ]},
            {PRNTS_ID: "111", MENU_ID: "1112", MENU_NM: "M-1112", child: []},
            {PRNTS_ID: "111", MENU_ID: "1113", MENU_NM: "M-1113", child: [
                {PRNTS_ID: "1113", MENU_ID: "11131", MENU_NM: "M-11131", child: []},                                                         
                {PRNTS_ID: "1113", MENU_ID: "11132", MENU_NM: "M-11132", child: []},                                                         
                {PRNTS_ID: "1113", MENU_ID: "11133", MENU_NM: "M-11133", child: []}                                                         
            ]}
        ]},
        {PRNTS_ID: "11", MENU_ID: "112", MENU_NM: "M-112", child: []}
    ]}
]};

function navigate() { 
	navigateDepthFirst(
			MENU,
			function(data) {
	            console.log(data.PRNTS_ID + "," + data.MENU_ID + "," + data.MENU_NM);
			});
}

var LIST = 
[
{PRNTS_ID: "", MENU_ID: "1", MENU_NM: "M-1"},
{PRNTS_ID: "1", MENU_ID: "11", MENU_NM: "M-11"},
{PRNTS_ID: "11", MENU_ID: "111", MENU_NM: "M-111"},
{PRNTS_ID: "111", MENU_ID: "1111", MENU_NM: "M-1111"},
{PRNTS_ID: "1111", MENU_ID: "11111", MENU_NM: "M-11111"},                                                         
{PRNTS_ID: "1111", MENU_ID: "11112", MENU_NM: "M-11112"},                                                         
{PRNTS_ID: "1111", MENU_ID: "11113", MENU_NM: "M-11113"},                                                         
{PRNTS_ID: "111", MENU_ID: "1112", MENU_NM: "M-1112"},
{PRNTS_ID: "111", MENU_ID: "1113", MENU_NM: "M-1113"},
{PRNTS_ID: "1113", MENU_ID: "11131", MENU_NM: "M-11131"},                                                         
{PRNTS_ID: "1113", MENU_ID: "11132", MENU_NM: "M-11132"},                                                         
{PRNTS_ID: "1113", MENU_ID: "11133", MENU_NM: "M-11133"},                                                         
{PRNTS_ID: "11", MENU_ID: "112", MENU_NM: "M-112"}
];

function convert() {
	var arr = arrayToTree(
					LIST, // data
					{parentKey:"PRNTS_ID", key:"MENU_ID", parent:"parent", child:"child"},
				    "1" // rootKey
				    );
	
	console.debug(arr);
}
</script>
</head>
<body>
<button type="button" id="btnAdd" onclick="navigate()">navigate</button><br/>
<button type="button" id="btnAdd" onclick="convert()">convert</button>
</body>
</html>